package com.example.tangjiangxu.lifecycle.lifecycle;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.example.tangjiangxu.lifecycle.R;

public class LifecycleActivity extends Activity {
    private final static String TAG = "LifecycleActivity";
    private Button bnClick;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (savedInstanceState != null) {
            String name = savedInstanceState.getString("name");
            Log.e(TAG, "onCreate name:" + name);
        }
        Log.i(TAG, "onCreate");
        setContentView(R.layout.activity_lifecycle);
        bnClick = (Button) this.findViewById(R.id.bnClick);
        new Thread(new Runnable() {
            @Override
            public void run() {
                bnClick.setText("自线程更改UI");
            }
        }).start();
        bnClick.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               Intent intent = new Intent(LifecycleActivity.this, SecondActivity.class);
                startActivity(intent);

                /*／／对话框不会影响Activity的任何生命周期
                AlertDialog.Builder builder = new AlertDialog.Builder(LifecycleActivity.this);
                builder.setTitle("标题")
                        .setMessage("内容")
                        .show();*/

            }
        });

    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.i(TAG, "onRestart");
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.i(TAG, "onStart");
    }

    @Override
    public void onConfigurationChanged(Configuration c) {
        super.onConfigurationChanged(c);
        Log.i(TAG, "onConfigurationChanged：");
    }

    @Override
    protected void onRestoreInstanceState(Bundle bundle) {
        super.onRestoreInstanceState(bundle);
        Log.i(TAG, "onRestoreInstanceState：");
        String name = bundle.getString("name");
        Log.e(TAG, "onRestoreInstanceStat name:" + name);
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.i(TAG, "onResume");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.i(TAG, "onPause");
    }

    @Override
    protected void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        Log.i(TAG, "onSaveInstanceState");
        bundle.putString("name", "josan");
    }


    @Override
    protected void onStop() {
        super.onStop();
        Log.i(TAG, "onStop");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "onDestroy");
    }


}
